package com.ht.module.bus.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.util.CollectionUtils;
import com.ht.module.bus.service.IBusResourceService;
import com.ht.util.*;
import com.ht.module.bus.entity.BusResource;

import javax.validation.Valid;
import java.io.IOException;
import java.util.*;


/**
 * <p>
 * 资源表 前端控制器
 * </p>
 *
 * @author hejialun
 * @since 2021-08-11
 */
@Api(tags = "资源表 ")
@RestController
@RequestMapping("/bus-resource")
public class BusResourceController {

    
    @Autowired
    private IBusResourceService iBusResourceService;

    


    /**
    * 分页查询
    */
    @ApiOperation(value = "分页查询")
    @GetMapping("/findPage")
    public JsonResult findPage(Pager<BusResource> pager, BusResource busResource){
        return JsonResult.success(iBusResourceService.page(pager));
    }

    /**
     * 分页查询我的图片资源
     */
    @ApiOperation(value = "分页查询我能使用的图片资源")
    @GetMapping("/findPageByMe")
    public JsonResult findPageByMe(Pager<BusResource> pager, BusResource en){
        return JsonResult.success(iBusResourceService.findPageByMe(pager,en));
    }



    /**
    * 通过id查询
    */
    @GetMapping("/get-by-id/{id}")
    @ApiOperation(value = "通过id查询")
    public JsonResult getById(@PathVariable(value = "id") String id){
        return JsonResult.success(iBusResourceService.getById(id));
    }

    /**
    * 新增
    */
    @PostMapping("/add")
    @ApiOperation(value = "新增")
    public JsonResult add(@Valid BusResource busResource) throws IOException {
        iBusResourceService.add(busResource);
        return JsonResult.success();
    }

    /**
    * 通过id删除
    */
    @DeleteMapping("/delete-by-id/{id}")
    @ApiOperation(value = "删除")
    public JsonResult delete(@PathVariable(value = "id") String id){

        iBusResourceService.delById(id);
        return JsonResult.success();
    }

    /**
    * 修改
    */
    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public JsonResult updateById(@RequestBody @Valid BusResource busResource){
        CommMethod.beanUpdate(busResource);
        iBusResourceService.updateById(busResource);
        return JsonResult.success();
    }

}
